import request from '@/utils/axios'

/**
 * 商品相关API接口
 */
export const goodsApi = {
  // 获取商品列表
  getGoodsList(params) {
    return request({
      url: '/goods/list',
      method: 'get',
      params
    })
  },

  // 获取商品详情
  getGoodsDetail(goodsId) {
    return request({
      url: `/goods/detail/${goodsId}`,
      method: 'get'
    })
  },

  // 发布商品
  publishGoods(data) {
    return request({
      url: '/goods/publish',
      method: 'post',
      data
    })
  },

  // 更新商品信息
  updateGoods(goodsId, data) {
    return request({
      url: `/goods/update/${goodsId}`,
      method: 'put',
      data
    })
  },

  // 删除商品
  deleteGoods(goodsId) {
    return request({
      url: `/goods/delete/${goodsId}`,
      method: 'delete'
    })
  },

  // 获取我的商品
  getMyGoods(params) {
    return request({
      url: '/goods/my-goods',
      method: 'get',
      params
    })
  },

  // 上传商品图片
  uploadImage(file) {
    const formData = new FormData()
    formData.append('file', file)
    
    return request({
      url: '/upload/image',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 获取热门商品
  getHotGoods(limit = 10) {
    return request({
      url: '/goods/hot',
      method: 'get',
      params: { limit }
    })
  },

  // 获取推荐商品
  getRecommendGoods(limit = 10) {
    return request({
      url: '/goods/recommend',
      method: 'get',
      params: { limit }
    })
  },

  // 增加浏览量
  increaseViewCount(goodsId) {
    return request({
      url: `/goods/view/${goodsId}`,
      method: 'post'
    })
  }
}